'use strict';

var permissionImpl = require('./dao_impl/permission.js');
var ferror = require('../common/app_utils.js').formatError;
var fout = require('../common/app_utils.js').formatOutput;
var errInfo = require('../common/err_info.js');
var debug = require('debug')('dao_permission');

var acl = require('./acl.js');
var permissions = require('../common/all_permissions.js');

function MongoDao() {
	var self = this instanceof MongoDao ? this : new MongoDao();
	return self;
}

module.exports = new MongoDao();
var theProto = MongoDao.prototype;

// create { "name":"vendor_add","code":123,"description":"添加商家"}
theProto.create = function(json) {
	return permissionImpl.create(json);
};

// userId
// should cache permissions TODO
theProto.readAll = function(json) {
	// return acl(json.userId, permissions.permission_read, null)

	// .then(function(result) {
	// 	if (result.errCode !== 0) {
	// 		return ferror(errInfo.E2203);
	// 	}
	// 	// have permission
	// 	var obj = {
	// 		query: {}
	// 	};
	// 	return permissionImpl.read(json);
	// });

	var obj = {
		query: {}
	};
	return permissionImpl.read(json);
};